<?php


namespace app\server\controller;

use app\server\model\GoodsOrder as GoodsOrderModel;
use app\index\controller\Base;
class Goodsorder extends Base
{
    /**
     * @根据订单相关条件进行查询
     */
    //搜索
    public function search()
    {
        $data = $this->request->param();
        $a = $data['name'];
        $res = new GoodsOrderModel();
        $r=$res->hasWhere('goods', function($query) use ( $a){
            $query->where('name', 'like', '%'.$a.'%');
        })
            ->with("goods,user")
            ->where($data['field'],$data['op'],$data['value'])
            ->select();
        return $r;
    }
    public function get()
    {
        $data = $this->request->param();
        $res = new GoodsOrderModel();
        $d=$res->with("goods,user,userAddress")
            ->where($data['field'],$data['op'],$data['value'])
            ->where($data['field1'],$data['op1'],$data['value1'])
            ->where($data['field2'],$data['op2'],$data['value2'])
            ->page($data['page'])
            ->limit(10)
            ->order('cTime desc')
            ->select();
        return $d;
    }

    /**
     * 添加一条goodsOrder内容
     */
    public function addGoodsOrder()
    {
        $res= new GoodsOrderModel();
        $data = $this->request->param();
        $res->saveModel($data);
    }

    /**
     * 删除订单内容
     */
    public function deleteGoodOrder()
    {
        $res=new GoodsOrderModel();
        $data = $this->request->param();
        $res->deleteModel($data);
    }
    /**
     * 更新订单内容
     */
    public function updateGoodsOrder()
    {
        $res = new GoodsOrderModel();
        $data = $this->request->param();
        return $res->updateModel($data);
    }
    public function num(){
        $data = $this->request->param();
        $res =new GoodsOrderModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }

}